<%--
  Created by IntelliJ IDEA.
  User: 86181
  Date: 2022/11/16
  Time: 15:34
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>点击调度</title>
</head>
<body>
<div class="modal-header">
    <button class="close" data-dismiss="modal">退出</button>
    <button onclick="paydispatchdangmodalbtn()" class="btn btn-primary">提交</button>
</div>
<div class="modal-body">
    <div class="row">
        <div class="col-md-offset-5"><h1><strong>出库调度单</strong></h1></div>
    </div>
    <br>
    <div class="row">
        <div class="col-md-6">
            <table>
                <tr>
                    <td>出库单编号:</td>
                    <td><input type="text" id="paydispatcjdamgmodalpayId" readonly style="outline: none;border: none"></td>
                </tr>
                <tr>
                    <td>产品名称:</td>
                    <td><input type="text" id="paydispatcjdamgmodalproductName" readonly style="outline: none;border: none"></td>
                </tr>
            </table>
        </div>
        <div class="col-md-6">
            <table>
                <tr>
                    <td>产品编号:</td>
                    <td><input id="paydispatcjdamgmodalproductId" type="text" readonly style="outline: none;border: none"></td>
                </tr>
                <tr>
                    <td>成本价格:</td>
                    <td><input id="paydispatcjdamgmodalcostPrice" type="text" readonly style="outline: none;border: none"></td>
                </tr>
            </table>
        </div>
    </div>
    <br>
    <div style="height:45%">
        <table id="paydisptchdangdumodaltab">
        </table>
    </div>
    <br>
    <div class="row">
        <div class="col-md-6">
            <table>
                <tr>
                    <td>应入库件数:</td>
                    <td><input type="text" id="paydispatcjdamgmodalamount" readonly style="outline: none;border: none"></td>
                </tr>
                <tr>
                    <td>登记人:</td>
                    <td><input type="text" id="paydispatcjdamgmodalattemper" value="${username}" required style="outline: none;border: none;border-bottom: 1px black dashed"></td>
                </tr>
            </table>
        </div>
        <div class="col-md-6">
            <table>
                <tr>
                    <td>已入库件数:</td>
                    <td><input type="text" id="paydispatcjdamgmodalpaidAmount" readonly style="outline: none;border: none"></td>
                </tr>
                <tr>
                    <td>登记时间:</td>
                    <td><input type="text" id="paydispatcjdamgmodalattemperTime" readonly style="outline: none;border: none;"></td>
                </tr>
            </table>
        </div>
    </div>
</div>
            <script>
                var id='${param.id}'
                //加载表格
                $(function () {
                    $("#paydisptchdangdumodaltab").bootstrapTable({
                        sortable: true,//是否显示排序
                        sortOrder: "aso",//排序方式
                        sidePagination:"server", //分页方式：client客户端分页，server服务端分页（*）
                        showColumns: true,//是否显示所有的列（选择显示的列）
                        showRefresh: true,//是否显示刷新按钮
                        minimumCountColumns: 2,//最少允许的列数
                        showToggle: true,//是否显示详细视图和列表视图的切换按钮
                        cardView: false,//是否显示详细视图
                        detailView: false,//是否显示父子表,
                        columns:[
                            {
                                field:"",
                                title:"编号",
                                formatter:function (value,row,index) {
                                    return Number(index)+1
                                }
                            },
                            {
                                field:"amount",
                                title:"当前库存数量",
                            },
                            {
                                field:"",
                                title:"本次出库数量",
                                formatter:function (value,row,index) {
                                    return "<input type='text' class='paydispachdangmodalchange' style='outline: none;'>"
                                }
                            },
                        ]


                    })
                    //查询当前当前出库的产品
                    //获取值
                    var productId='${param.productId}'
                    $.post("queryBypayDetailsByid.action",{"id":id,"productId":productId},function (data) {
                        //出库编号
                        $("#paydispatcjdamgmodalpayId").val(data.pay.payId)
                        //产品名称
                        $("#paydispatcjdamgmodalproductName").val(data.productName)
                        //产品编号
                        $("#paydispatcjdamgmodalproductId").val(data.productId)
                        //成本价格
                        $("#paydispatcjdamgmodalcostPrice").val(data.costPrice)
                        //应出库量
                        $("#paydispatcjdamgmodalamount").val(data.amount)
                        //已出库数量
                        $("#paydispatcjdamgmodalpaidAmount").val(data.paidAmount)

                        //点击获取当前时间
                        $("#paydispatcjdamgmodalattemperTime").val(data.pay.registerTime)
                        //登记
                        $("#paydispatcjdamgmodalattemper").val(data.pay.register)
                        //表格赋值
                        var arr={
                            amount:data.cell.amount,
                        }

                        $("#paydisptchdangdumodaltab").bootstrapTable("append",arr)
                    },"json")
                })
                //提交
                function paydispatchdangmodalbtn() {
                    var num=$(".paydispachdangmodalchange").val();
                    var nums=$(".paydispachdangmodalchange").parent().parent().find("td").eq(1).text();
                    var amount=$("#paydispatcjdamgmodalamount").val();
                    //验证数字
                    var reg=/^[0-9]*$/
                    if(!reg.test(num)){
                        alert("请输入正确的数字")
                        return;
                    }
                    if(Number(num)!=Number(amount)){
                        alert("出库数量不一致")
                        return
                    }
                    if(num>Number(nums)){
                        alert("库存数量不足")
                        return;
                    }
                    //修改状态
                    $.post("updatepayDetailsfuid.action",{"id":id,"productId":$("#paydispatcjdamgmodalproductId").val()},function (data) {
                        alert(data.msg)
                        $("#paydisptchdangdumodal").modal("hide")
                        jiazaigatherson();
                    },"json")
                }
            </script>
</body>
</html>
